package org.openems.otdr;

import org.openems.PrimitiveTraceEntity;
import org.openems.model.OtdrResultModel;
import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Key;

public class OtdrTrace {

    public PrimitiveTraceEntity get(String key, int points) {
        Key k = Datastore.stringToKey(key);
        
        OtdrResultModel res = Datastore.get(OtdrResultModel.class, k);
        PrimitiveTraceEntity ret = new PrimitiveTraceEntity();

        double[] trace = res.getTrace();
        double step = (double)trace.length / (double)points;
        for (double i = 0; i < trace.length; i += step) {
            ret.y.add(trace[(int)i]);
        }
        
        for (double d : res.getTrace()) {
            ret.y.add(d);
        }
        ret.horizontalMax = (double)ret.y.size();
        ret.horizontalMin = 0.0;
        return ret;
    }

}
